<template>
  <div v-loading="loading" class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('交易条款') }}</span>
    </div>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-table :data="form.transactionTermsList" border class="nowrapTable formTable tree_el_Table">
        <el-table-column :label="$t('序号')" align="center" type="index" width="50" />
        <el-table-column :label="$t('交易条款')" align="center" prop="exchangeProvision" width="150" :formatter="exchangeProvisionFormat" />
        <el-table-column :label="$t('管控内容')" align="left" prop="controlTheContent">
          <template slot-scope="scope">
            <el-input v-model="scope.row.controlTheContent" type="textarea" show-word-limit maxlength="2000" />
          </template>
        </el-table-column>
      </el-table>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: center;">
      <!--保存 取消按钮-->
      <save-btn has-permi="deal:transactionTerms" :cancel-show="false" />
    </div>
  </div>
</template>

<script>
    import { saveTransactionTerms, listTransactionTerms, init } from '@/api/deal/estate/transactionTerms/transactionTerms'
    export default {
        data() {
            return {
                // 表单参数
                form: {
                  // 基金清算数据
                  transactionTermsList: []
                },
                // 交易条款
                exchangeProvision: [],
                // 项目类型为夹层项目交易条款字典
                exchangeProvisionJc: [],
              // 项目类型为其他项目交易条款字典
                exchangeProvisionQT: [],
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                controlTheContent: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ]
                }
            }
        },
      mounted() {
        this.$bus.$emit('async_done')
      },
        created() {
          this.getDicts('exchange_provision_jc').then(response => {
            this.exchangeProvisionJc = response.data
          })
          this.getDicts('exchange_provision_equity').then(response => {
            this.exchangeProvisionQT = response.data
          })
        },
        methods: {
            // 初始化数据
            init() {
                this.loading = true
              listTransactionTerms(this.$route.query.id).then(response => {
                debugger
                if (response.data.dealId !== null) {
                  this.form = response.data
                  this.loading = false
                } else {
                  init(this.$route.query.id).then(response => {
                    this.form = response.data
                    this.form.dealId = this.$route.query.id
                    this.loading = false
                  })
                }
              })
            },
          exchangeProvisionFormat(row) {
              if (this.form.exchangeProvisionData === 'exchange_provision_jc') {
                return this.selectDictLabel(this.exchangeProvisionJc, row.exchangeProvision)
              } else {
                return this.selectDictLabel(this.exchangeProvisionQT, row.exchangeProvision)
              }
          },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                      debugger
                        saveTransactionTerms(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                })
           }

        }

    }
</script>
